package com.glodon.paas.monitor.server.biz.service.impl;

import java.util.ArrayList;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.glodon.paas.monitor.server.biz.domain.MonitorAlarmRulesEntity;
import com.glodon.paas.monitor.server.biz.mapper.MonitorAlarmRulesMapper;
import com.glodon.paas.monitor.server.biz.service.MonitorAlarmRulesService;
import com.glodon.paas.monitor.server.dto.MonitorAlarmRulesDTO;
import com.glodon.paas.monitor.server.exception.MonitorException;

@Service("monitorAlarmRulesService")
public class MonitorAlarmRulesServiceImpl implements MonitorAlarmRulesService {

	@Autowired
	private MonitorAlarmRulesMapper	monitorAlarmRulesMapper;

	public int deleteByPrimaryKey(Long id) {
		if (null == id) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"deleteByPrimaryKey alarmRules id is null!");
		}
		return monitorAlarmRulesMapper.deleteByPrimaryKey(id);
	}

	public int insert(MonitorAlarmRulesEntity record) {
		if (null == record || StringUtils.isBlank(record.getAlarmName())) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID, "insert alarmRules record is null!");
		}
		return monitorAlarmRulesMapper.insert(record);
	}

	public int insertSelective(MonitorAlarmRulesEntity record) {
		if (null == record || StringUtils.isBlank(record.getAlarmName())) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"insertSelective alarmRules record is null!");
		}
		return monitorAlarmRulesMapper.insertSelective(record);
	}

	public MonitorAlarmRulesEntity selectByPrimaryKey(Long id) {
		if (null == id) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"selectByPrimaryKey alarmRules id is null!");
		}
		return monitorAlarmRulesMapper.selectByPrimaryKey(id);
	}

	public int updateByPrimaryKeySelective(MonitorAlarmRulesEntity record) {
		if (null == record || null == record.getId()) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"updateByPrimaryKeySelective alarmRules record is null!");
		}
		return monitorAlarmRulesMapper.updateByPrimaryKeySelective(record);
	}

	public int updateByPrimaryKey(MonitorAlarmRulesEntity record) {
		if (null == record || null == record.getId()) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"updateByPrimaryKey alarmRules record is null!");
		}
		return monitorAlarmRulesMapper.updateByPrimaryKey(record);
	}

	@Override
	public ArrayList<MonitorAlarmRulesEntity> queryMonitorAlarm(MonitorAlarmRulesDTO monitorAlarmRulesDTO) {
		if (null == monitorAlarmRulesDTO) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"selectByAlarmName alarmRules monitorAlarmRulesDTO is null!");
		}
		return monitorAlarmRulesMapper.queryMonitorAlarm(monitorAlarmRulesDTO);
	}

	@Override
	public int deleteByItemId(Long itemId) {
		if (null == itemId) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"deleteByPrimaryKey alarmRules id is null!");
		}
		return monitorAlarmRulesMapper.deleteByItemId(itemId);
	}

}
